/*
package com.quanyan.search.service.impl;


import com.quanyan.api.APIResponse;
import com.quanyan.common.constants.SearchConstants;
import com.quanyan.search.entity.vo.PlaceSalePlanInfo;
import com.quanyan.search.mapper.SearchPlaceDisplayMapper;
import com.quanyan.search.service.PlaceSalePlanSearchService;
import com.quanyan.search.utils.CommonUtil;
import com.quanyan.search.utils.SolrServerSingle;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.MapSolrParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;


*/
/**
 * PlaceSearchServiceImpl
 * 搜索服务实现
 *
 * @author Tu Chun
 * @date 2016/6/3
 *//*

@Service("placeSalePlanSearchService")
public class PlaceSalePlanSearchServiceImpl implements PlaceSalePlanSearchService {
    private static Logger logger = LoggerFactory.getLogger(PlaceSalePlanSearchServiceImpl.class);
    //public final static String URL = "http://192.168.30.181:8080/solr";
    //public final static String URL = "192.168.30.181:2181,192.168.30.181:2182,192.168.30.181:2183";
    //public   static String URL = "192.168.30.75:2181,192.168.30.75:2182,192.168.30.75:2183";
    private String URL;

    public String getURL() {
        return URL;
    }

    public void setURL(String URL) {
        this.URL = URL;
    }

    @Autowired
    private SearchPlaceDisplayMapper searchPlaceDisplayMapper;


    public PlaceSalePlanSearchServiceImpl(String url) {
        this.URL = url;
    }

    public PlaceSalePlanSearchServiceImpl() {
    }

    */
/**
     * 添加场馆售卖计划索引
     *
     * @param insertPlaceSalePlanInfo
     * @return
     *//*

    @Override
    public APIResponse insertDoc(PlaceSalePlanInfo insertPlaceSalePlanInfo) {
        try {
            if (addDocUtil(insertPlaceSalePlanInfo)) {
                return APIResponse.returnSuccess("添加场馆售卖计划" + insertPlaceSalePlanInfo.getSale_id() + "索引c成功");
            } else {
                return APIResponse.returnFail("添加场馆售卖计划索引失败");
            }
        } catch (Exception e) {
            logger.error(e.getMessage() + "添加场馆售卖计划索引失败", e);
            return APIResponse.returnFail("添加场馆售卖计划索引失败");
        }
    }

    */
/**
     * 添加多个场馆售卖计划索引
     *
     * @param insertPlaceSalePlanInfos
     * @return
     *//*

    @Override
    public APIResponse insertDocs(List<PlaceSalePlanInfo> insertPlaceSalePlanInfos) {
        try {
            for (int i = 0; i < insertPlaceSalePlanInfos.size(); i++) {
                PlaceSalePlanInfo insertPlaceSalePlanInfo = insertPlaceSalePlanInfos.get(i);
                addDocUtil(insertPlaceSalePlanInfo);
            }
            return APIResponse.returnSuccess("添加多个场馆售卖计划索引成功");
        } catch (Exception e) {
            logger.error(e.getMessage() + "添加多个场馆售卖计划索引异常", e);
            return APIResponse.returnFail("添加多个场馆售卖计划索引失败");
        }

    }

    */
/**
     * 根据id删除Document
     *
     * @param id
     * @return
     *//*

    @Override
    public APIResponse deleteDocById(Integer id) {
        try {
            //创建连接
            CloudSolrServer solrServer = SolrServerSingle.getInstance(URL);
            // 设置默认的collection
            solrServer.setDefaultCollection("collection2");
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("sale_id:").append(id);
            solrServer.deleteByQuery(stringBuilder.toString());
            solrServer.commit();
            return APIResponse.returnSuccess("删除场馆售卖计划索引成功");
        } catch (Exception e) {
            logger.error(e.getMessage() + "删除场馆售卖计划索引异常", e);
            return APIResponse.returnFail("删除场馆售卖计划索引失败");
        }
    }


    */
/**
     * 删除多个Document
     *
     * @param ids
     * @return
     *//*

    @Override
    public APIResponse deleteDocsByIds(List<Integer> ids) {

        try {
            for (int i = 0; i < ids.size(); i++) {
                Integer id = ids.get(i);
                //创建连接
                CloudSolrServer solrServer = SolrServerSingle.getInstance(URL);
                // 设置默认的collection
                solrServer.setDefaultCollection("collection2");
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("sale_id:").append(id);
                solrServer.deleteByQuery(stringBuilder.toString());
                solrServer.commit();
            }
            return APIResponse.returnSuccess("删除多个场馆售卖计划索引成功");

        } catch (Exception e) {
            logger.error(e.getMessage() + "删除多个场馆售卖计划索引异常", e);
            return APIResponse.returnFail("删除多个场馆售卖计划索引失败");
        }


    }


    */
/**
     * 根据id获取场馆售卖计划信息
     *
     * @param id
     * @return
     *//*

    @Override
    public APIResponse<PlaceSalePlanInfo> searchPlaceSalePlanInfo(Integer id) {
        try {
            //创建连接
            CloudSolrServer solrServer = SolrServerSingle.getInstance(URL);
            // 设置默认的collection
            solrServer.setDefaultCollection("collection2");
            Map<String, String> params = new HashMap<String, String>();
            StringBuilder builder = new StringBuilder();
            builder.append("place_id:").append(id);
            params.put("q", builder.toString());
            QueryResponse response = solrServer.query(new MapSolrParams(params), SolrRequest.METHOD.POST);
            SolrDocumentList solrDocumentList = response.getResults();
            List<PlaceSalePlanInfo> PlaceSalePlanInfoList = response.getBeans(PlaceSalePlanInfo.class);
            return APIResponse.returnSuccess(CommonUtil.isNullOrZero(PlaceSalePlanInfoList) ? null : PlaceSalePlanInfoList.get(0));
        } catch (Exception e) {
            logger.error(e.getMessage() + "根据id搜索场馆售卖计划异常", e);
            return APIResponse.returnFail("根据id搜索场馆售卖计划失败");
        }
    }




    private boolean addDocUtil(PlaceSalePlanInfo indexInfo) {
        try {
            //创建连接
            CloudSolrServer solrServer = SolrServerSingle.getInstance(URL);
            // 设置默认的collection
            solrServer.setDefaultCollection("collection2");
            //创建文档对象
            SolrInputDocument document = new SolrInputDocument();
            String uniqueId = SearchConstants.SALE_ID_PREFIX + UUID.randomUUID().toString();
            document.addField("sale_id", uniqueId);
            document.addField("sale_place_id", indexInfo.getSale_place_id());
             document.addField("sale_startTime", CommonUtil.getSolrDate(indexInfo.getSale_startTime()));
            document.addField("sale_endTime", CommonUtil.getSolrDate( indexInfo.getSale_endTime()));
            document.addField("sale_flag", indexInfo.getSale_flag());

            solrServer.add(document);
            solrServer.commit();
            logger.info("添加场馆售卖计划索引成功");
            return true;
        } catch (Exception e) {
            logger.error(e.getMessage() + "添加场馆售卖计划索引失败", e);
            return false;
        }
    }
}
*/
